//
//  RateView.swift
//  GhostWorld
//
//  Created by Kam on 2018/6/29.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

protocol RateViewDelegate {
  func rate()
}

class RateView: UIView {

  var delegate: RateViewDelegate?
  
  func set(rate: Int) {
    var theRate = rate
    if theRate < 0 {
      theRate = 0
    }
    if theRate > 5 {
      theRate = 5
    }
    for index in 1...5 {
      let button = viewWithTag(index) as! UIButton
      if index <= theRate {
        button.setImage(UIImage(named: "PlayerRateStarLight"), for: .normal)
      } else {
        button.setImage(UIImage(named: "PlayerRateStarDark"), for: .normal)
      }
    }
  }
  
  @IBAction func rate() {
    delegate?.rate()
  }
}
